package cn.demo.um.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import cn.demo.common.annotation.Log;
import cn.demo.common.core.controller.BaseController;
import cn.demo.common.core.domain.R;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import cn.demo.common.enums.BusinessType;
import cn.demo.um.domain.UmWeddingGift;
import cn.demo.um.service.IUmWeddingGiftService;
import cn.demo.common.utils.poi.ExcelUtil;
import cn.demo.common.core.page.PageR;
import cn.demo.common.core.page.PageQuery;
import com.mybatisflex.core.paginate.Page;


/**
 * 用户领证贺礼Controller
 *
 * @author xtjun
 * @date 2024-07-03
 */
@Tag(name = "用户领证贺礼")
@RestController
@RequestMapping("/um/umWeddingGift")
public class UmWeddingGiftController extends BaseController {
    @Resource
    private IUmWeddingGiftService umWeddingGiftService;

    @Operation(summary = "查询用户领证贺礼列表")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:list')")
    @GetMapping("/list")
    public PageR<UmWeddingGift> list(UmWeddingGift umWeddingGift, PageQuery pageQuery) {
        Page<UmWeddingGift> page = umWeddingGiftService.selectUmWeddingGiftPage(umWeddingGift, pageQuery);
        return PageR.ok(page);
    }

    @Operation(summary = "导出用户领证贺礼列表")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:export')")
    @Log(title = "用户领证贺礼", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UmWeddingGift umWeddingGift) {
        List<UmWeddingGift> list = umWeddingGiftService.selectUmWeddingGiftList(umWeddingGift);
        ExcelUtil<UmWeddingGift> util = new ExcelUtil<UmWeddingGift>(UmWeddingGift.class);
        util.exportExcel(response, list, "用户领证贺礼数据");
    }

    @Operation(summary = "获取用户领证贺礼详细信息")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:query')")
    @GetMapping(value = "/{id}")
    public R<UmWeddingGift> getInfo(@PathVariable("id") String id) {
        return R.ok(umWeddingGiftService.selectUmWeddingGiftById(id));
    }

    @Operation(summary = "新增用户领证贺礼")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:add')")
    @Log(title = "用户领证贺礼", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody UmWeddingGift umWeddingGift) {
        return toAjax(umWeddingGiftService.insertUmWeddingGift(umWeddingGift));
    }

    @Operation(summary = "修改用户领证贺礼")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:edit')")
    @Log(title = "用户领证贺礼", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody UmWeddingGift umWeddingGift) {
        return toAjax(umWeddingGiftService.updateUmWeddingGift(umWeddingGift));
    }

    @Operation(summary = "删除用户领证贺礼")
    @PreAuthorize("@ss.hasPermi('um:umWeddingGift:remove')")
    @Log(title = "用户领证贺礼", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable List<String> ids) {
        return toAjax(umWeddingGiftService.deleteUmWeddingGiftByIds(ids));
    }
}
